package gbench.appdemo.myworld.economy.demand;

import java.time.LocalDateTime;
import java.util.concurrent.atomic.AtomicLong;

import gbench.appdemo.myworld.economy.society.Individual;
import gbench.common.tree.LittleTree.CronTime;
import lombok.Data;

/**
 * 
 * @author gbench
 *
 */
@Data
public class Demand implements IDemand{
    
    /**
     * 
     * @param id
     * @param type
     * @param name
     * @param time
     * @param expiredTime
     */
    public Demand(String id, String type, String name, LocalDateTime time, Long expiredTime) {
        super();
        this.id = id;
        this.type = type;
        this.name = name;
        this.time = time;
        this.expiredTime = expiredTime;
    }

    public Demand() {
        super();
    }
    
    /**
     * 
     */
    @Override
    public String getId() {
        return id;
    }
    
    /**
     * 
     */
    @Override
    public String getType() {
        return type;
    }
    
    /**
     * 
     */
    @Override
    public LocalDateTime getTime() {
        return time;
    }
    
    /**
     * 
     */
    @Override
    public Long getExpiredTime() {
        return expiredTime;
    }
    
    /**
     * 
     */
    public String getName() {
        return this.name;
    }
    
    @Override
    public boolean isResolved() {
        return resolvedTime == null;
    }

    @Override
    public void resolve() {
        this.resolvedTime  = LocalDateTime.now();
    }
    
    @Override
    public Double score() {
        if(!this.isResolved()) return 0d;
        return 1-CronTime.ldt2dt(this.resolvedTime).getTime()*1.0/this.expiredTime;
    }
    
    @Override
    public Individual Owner() {
        return owner;
    }

    @Override
    public Double getQuantity() {
        return quantity;
    }

    private String id = ai.getAndIncrement() + "";
    private String type = "-";
    private String name = "-";
    private LocalDateTime time = LocalDateTime.now();
    private Long expiredTime = 10000000l;
    private LocalDateTime resolvedTime = null;
    private Individual owner = null;
    private Double quantity = 0d;
    
    public static AtomicLong ai = new AtomicLong();

   
}
